function fidSignal = GET_FIDSignal(obj, varargin)
%GET_FIDSIGNAL Summary of this function goes here
%   Detailed explanation goes here
    expected_nuclearName={'129', '131', 'both'};
    p=inputParser;
    p.addParameter('isotope', 'both', @(x) any(validatestring(x,expected_nuclearName)) );
    p.addParameter('sampling_rate', 12, @isnumeric);
    p.addParameter('frame_time', 60.0, @isnumeric);
    p.addParameter('addToSession', false, @islogical);
    p.addParameter('isPlot', false, @islogical);
    p.addParameter('signal_channel', obj.controller.DemodSettings.ByDemodFast.index, @(x) ismember(x, {'0', '1', '2', '3'}));
    p.addParameter('signal_component', 'x', @(x) ismember(x, {'x', 'y'}));
    p.parse(varargin{:});

    L=log4m.getLogger;
    L.info('XeNMRSystem::GET_FIDSignal', sprintf('NMR %s FID measurement started.', p.Results.isotope));
    
    obj.controller.setMagnetometerFastDemodRate(); % set demode channel rate (use default)

    plt = obj.controller.ziMaster.plotterModule;
    plt.reset();
    plt.subscribeChannel(p.Results.signal_channel, {p.Results.signal_component});

    switch p.Results.isotope
        case '129'
            obj.controller.disableNMRDriving131();
            L.info('XeNMRSystem::GET_FIDSignal', sprintf('Waiting for Pre-relaxation (%d seconds)', 120) );
            pause(120);
            obj.controller.disableNMRDriving129();
            fidSignal = plt.run('window_time', p.Results.frame_time, 'total_duration', p.Results.frame_time, 'single_poll_duration', p.Results.frame_time);
            obj.controller.enableNMRDriving129();
            obj.controller.enableNMRDriving131();
        case '131'
            obj.controller.disableNMRDriving129();
            L.info('XeNMRSystem::GET_FIDSignal', sprintf('Waiting for Pre-relaxation (%d seconds)', 120) );
            pause(120);
            obj.controller.disableNMRDriving131();
            fidSignal = plt.run('window_time', p.Results.frame_time, 'total_duration', p.Results.frame_time, 'single_poll_duration', p.Results.frame_time);
            obj.controller.enableNMRDriving129();
            obj.controller.enableNMRDriving131();
        case 'both'
            obj.controller.disableNMRDriving129();
            obj.controller.disableNMRDriving131();
            fidSignal = plt.run('window_time', p.Results.frame_time, 'total_duration', p.Results.frame_time, 'single_poll_duration', p.Results.frame_time);
            obj.controller.enableNMRDriving129();
            obj.controller.enableNMRDriving131();
    end
    plt.unsubscribeChannel();

    if p.Results.addToSession
        scp.addToSession(['XeFIDSignal', p.Results.isotope]);
    end

    if p.Results.isPlot
        fid_data=fidSignal.getNodeData(p.Results.signal_channel, {p.Results.signal_component});
        
        fig = figure('Name', 'FID'); ax = axes(fig);
        plot(ax, fid_data.time, fid_data.value, '.b', 'linewidth', 1.5);
        grid on;
        title(ax, ['fidNMR', p.Results.isotope]);
        xlabel(ax, 'Time (s)'); ylabel(ax, 'Amplitude');
        ylim(ax, [-1.1*max(abs(fid_data.value)), 1.1*max(abs(fid_data.value))]);
    end
    
    L.info('XeNMRSystem::GET_FIDSignal', sprintf('NMR %s FID measurement finished.', p.Results.isotope));
end

